package com.koron.css2.serviceManage.impl;

import com.koron.css2.ServerInterface;
import com.koron.css2.serviceManage.bean.DictionaryListBean;
import com.koron.css2.serviceManage.bean.RequestBean;
import com.koron.css2.serviceManage.bean.UserInfoBean;
import com.koron.css2.serviceManage.mapper.DictionaryMapper;
import com.koron.util.Constant;
import com.koron.util.JsonUtils;
import org.apache.commons.lang3.StringUtils;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import org.koron.ebs.mybatis.SessionFactory;
import org.swan.bean.MessageBean;

import java.util.List;

/**
* 删除参数/类型信息
* @author DaiSn
* @version 创建时间：2018年12月19日 上午10:40:09
*/
public class DictionaryParamInfoDelete implements ServerInterface {
	private static Logger logger = LogManager.getLogger(DictionaryParamInfoDelete.class);

	@Override
	public MessageBean<?> exec(SessionFactory factory, UserInfoBean userInfo, RequestBean req) {

		@SuppressWarnings("rawtypes")
		MessageBean<List> info = MessageBean.create(Constant.MESSAGE_INT_SUCCESS, "success", List.class);
		try {
			DictionaryListBean bean = new DictionaryListBean();
			DictionaryMapper mapper = factory.getMapper(DictionaryMapper.class);
			bean = JsonUtils.objectToPojo(req.getData(), DictionaryListBean.class);
			if(StringUtils.isBlank(bean.getId())){
				return MessageBean.create(Constant.ILLEGAL_PARAMETER, "非法参数", void.class);
			}
			mapper.delDictionaryParamInfo(bean);
			info.setCode(Constant.MESSAGE_INT_SUCCESS);
			info.setDescription("success");
		} catch (Exception e) {
			info.setCode(Constant.MESSAGE_DBFAIL);
			info.setDescription("数据库异常");
			logger.error("数据库异常",e);
			factory.close(false);
		}
		return info;
	}

}
